package com.lw.lost.daos

import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase

class ReportDao(private val db: SQLiteDatabase) {
    
    fun insert(userId: Long, targetId: Long, type: String, reason: String): Long {
        val values = ContentValues().apply {
            put("userId", userId)
            put("targetId", targetId)
            put("type", type)
            put("reason", reason)
            put("status", 0)  // 0: 待处理
            put("reportTime", System.currentTimeMillis())
        }
        return db.insert("reports", null, values)
    }

    fun getReports(): Cursor {
        return db.rawQuery("""
            SELECT r.*, 
                u1.name as reporterName,
                u2.name as targetName
            FROM reports r
            LEFT JOIN users u1 ON r.userId = u1.userId
            LEFT JOIN users u2 ON r.targetId = u2.userId
            ORDER BY r.reportTime DESC
        """, null)
    }

    fun updateStatus(reportId: Long, status: Int): Int {
        val values = ContentValues().apply {
            put("status", status)
        }
        return db.update("reports", values, "reportId = ?", arrayOf(reportId.toString()))
    }
} 